package xin.tianhui.cloud.weblog.service.impl;

import xin.tianhui.cloud.weblog.model.dto.ModelResultDTO;
import xin.tianhui.cloud.weblog.model.po.Model;
import xin.tianhui.cloud.weblog.mapper.ModelMapper;
import xin.tianhui.cloud.weblog.service.IModelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Optional;

import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 模型 服务实现类
 * </p>
 *
 * @author junchen
 * @since 2018-04-06
 */
@Service
@CacheConfig(cacheNames="model",keyGenerator="keyGenerator")
public class ModelServiceImpl extends ServiceImpl<ModelMapper, Model> implements IModelService {
	
	@Autowired
	private Mapper mapper;
	
	@Cacheable(key="'model:'+#modelId")
	@Override
	public ModelResultDTO getModel(Integer modelId) {
		Model model = baseMapper.selectById(modelId);
		return Optional.ofNullable(model).map(r ->{
			return mapper.map(r, ModelResultDTO.class);
		}).orElse(null);
	}
	
	
}
